package com.example.advice;

import com.example.pojo.ResultBean;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authz.AuthorizationException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 异常拦截器
 */
@RestControllerAdvice
public class ExceptionAdvice {

    /**
     * 处理Shiro登录异常
     * @param e
     * @return
     */
    @ExceptionHandler({UnknownAccountException.class, IncorrectCredentialsException.class})
    public ResultBean loginException(Exception e) {
        return ResultBean.error("账号或密码错误");
    }

    /**
     * 处理权限验证不通过异常
     * @param e
     * @return
     */
    @ExceptionHandler(AuthorizationException.class)
    public ResultBean authorizationException(Exception e) {
        return ResultBean.error("没有权限执行此操作");
    }
}
